import { GetServerSideProps } from 'next'
import FolderTemplate from '../../../components/templates/Folder'
import FolderPresenter from '../../../domains/Folder/presenter'
import {createDefaultAuth} from '../../../utilities/auth';
import {forGetServerSideProps} from '../../../utilities/handler'
import FolderViewMode from '../../../models/FolderViewMode'

const DescendantFolder = ({ children, items, mode, hierarchy, query, }) => {
	return (
		<FolderTemplate
			query={query}
			children={children}
			items={items}
			mode={mode}
			hierarchy={hierarchy}
		/>
	)
}

export const getServerSideProps: GetServerSideProps = forGetServerSideProps((ctx) => {
	const auth = createDefaultAuth()
	const session = auth.getSession(ctx.req, ctx.res)
	const folderController = new FolderPresenter()
	const {
		'q': query = '',
		'mode': mode = FolderViewMode.DEFAULT,
		'id': id,
	} = ctx.query
	return folderController.getDescendantFolderViewState({
		session,
		query,
		mode,
		id,
	})
})

export default DescendantFolder
